package com.partners.controller.Page;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.partners.annotation.Auths;
import com.partners.service.FansService;
import com.partners.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author liangyongle
 * @date 2018-12-05
 */
@Controller
@RequestMapping("fanspage")
@Slf4j
public class FansPageController {
    public final static String openid = "openId";
    @Resource
    private FansService fansService;

    //页面显示1
    @GetMapping("fansinfo")
    @Auths
    public ModelAndView fanInfo(HttpSession session) {
        Object user = session.getAttribute("openId");
        log.info("user{}",user);
        String nickname = "";
        if(user !=null){
            JSONObject jsonObject = JSON.parseObject(JsonUtils.toJson(user));
        }

        //Object fans = fansService.getFansInfoByOpenId(openId);
        ModelAndView mav=new ModelAndView("show/fans_info");
//        mav.addObject("nickname",jsonObject.getString("nickname"));
//        mav.addObject("openId",jsonObject.getString("openid"));
//        mav.addObject("avatar",jsonObject.getString("avatar"));
        return mav;
    }


    @GetMapping("fansList")
    public ModelAndView fansList(HttpSession session){
        String openId = (String) session.getAttribute("openId");
        log.info("session::{}",openId);
        if(openId == null){
            openId = "Forever10";
        }
        ModelAndView mav=new ModelAndView("show/fans_list");
        mav.addObject("openId",openId);
        return mav;
    }


}
